package kr.hkit.powerjava.chapter24.work.service;

import java.util.*;

import kr.hkit.powerjava.chapter24.work.*;

public abstract class DepartmentService extends ServiceItem<Department> {

	
	public DepartmentService(InterfaceDao<Department> dao, Scanner sc) {
		super(dao, sc);
	}

	@Override
	public Department inputItemInfo(boolean gubun) {
		System.out.println("학과번호 학과명");
		 Department dept = new Department( sc.nextInt(), sc.next().trim()); //trim() 양 사이즈 공백제거
		 if(gubun){
			 int floor = sc.nextInt();
			 dept.setFloor(floor);
		 }
		return dept;
	}

	@Override
	public void prnSubMenu() {
		System.out.println("1. 이름순 정렬 2. 위치별 정렬 3. 번호순 정렬");
		int res = sc.nextInt();
		switch(res){
			case 1:
				dao.prnItemList(new Comparator<Department>() {
					
					@Override
					public int compare(Department o1, Department o2) {
						return o1.getDeptName().hashCode() - o2.getDeptName().hashCode();
					}
				});
				break;
			case 2:
				dao.prnItemList(new Comparator<Department>() {
					
					@Override
					public int compare(Department o1, Department o2) {
						return o1.getFloor()-o2.getFloor();
					}
				});
				break;
			default:
				dao.prnItemList(null);
		}
	}

}
